#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m;
int a[N];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			int x;
			cin >> x;
			if (x == i)cnt++;
		}
		if (cnt & 1)cout << cnt / 2 + 1<< endl;
		else cout << cnt / 2 << endl;
		//cout << max(cnt - 1, 0) << endl;
	}
	return 0;
}